﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.orderDAL;
using dhDataAcess.dataAcess;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;

namespace dhSystemBLL.orderData
{
   public  class supplierTypeBLL
    {
      
       private supplierTypeTableAdapter _supplierTypeAdapter=null ;
       private supplierTypeTableAdapter supplierTypeAdapter
       {
        get
        {
            if (_supplierTypeAdapter == null) _supplierTypeAdapter = new supplierTypeTableAdapter();
            return _supplierTypeAdapter;
   }
        }
        /// <summary>
       /// 查询客户类别表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public orderDataSet.supplierTypeDataTable getsupplierTypeAll()
       {
           try 
           {
              return  supplierTypeAdapter.GetDatasupplierTypeAll();
           
           }
           catch (Exception ex)
           {
               throw new Exception (ex .Message .ToString ());
           }
       }
        /// <summary>
       /// 根据客户类别查询客户类别表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public orderDataSet.supplierTypeDataTable getsupplierTypeAll(string sType)
       {
           try
           {
               return supplierTypeAdapter.GetDatasupplierTypeBysType(sType);
           }
            catch (Exception ex)
           {
               throw new Exception (ex .Message .ToString ());
           }
       }
        /// <summary>
        /// 插入客户类别表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public int supplierTypeInsert(supplierTypeModel row)
       {
           int i = 0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
         
           try
           {
               tn = conn.BeginTransaction();
               supplierTypeDAL supplierType = new supplierTypeDAL(tn, conn);
               supplierType.supplierTypeInsert(row);
               tn.Commit();
               return i;
           }
           catch (SqlException ex)
           {
               tn.Rollback();
               if (ex.Number == 2627)
               {
                   throw new Exception("这个供应商类别已经存在");
               }


               throw new Exception(ex.Number.ToString() + ex.Message.ToString());

           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
               
           }
           finally
           {
               conn.Close();
           }
           
       }
        /// <summary>
        ///更新客户类别表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public int supplierTypeUpdate(supplierTypeModel row)
       {
           int i=0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
           try
           {
               tn = conn.BeginTransaction();
               supplierTypeDAL supplierType = new supplierTypeDAL(tn, conn);
               supplierType.supplierTypeUpdate(row);
               tn.Commit();
               return i;
           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
               
           }
           finally
           {
               conn.Close();
           }


       }
       /// <summary>
       ///删除客户类别表
       /// </summary>
       /// <param name="row"></param>
       /// <returns></returns>
       public int supplierTypeDel(string sType)
       {
           int i = 0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
           try
           {
               tn = conn.BeginTransaction();
               supplierTypeDAL supplierType = new supplierTypeDAL(tn, conn);
               supplierType.supplierTypeDel(sType);
               tn.Commit();
               return i;
           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
               
           }
           finally
           {
               conn.Close();
           }
       }
    }
}
